/**
 * 
 */
package cyclopean;

import java.awt.DisplayMode;
import java.awt.GraphicsEnvironment;
import java.io.File;

import javagame.core.properties.AutoProperties;

// TODO Javadoc
/**
 * 
 *
 * @author Jaco van der Westhuizen
 */
public class VideoProperties extends AutoProperties
{
	public static int RES_X = 800;
	public static int RES_Y = 600;
	public static int BIT_DEPTH = 32;
	public static int REFRESH_RATE = 60;
	public static boolean FULLSCREEN = false;
	public static String ASPECT_RATIO = "4:3";

	static
	{
		load(VideoProperties.class, new File("video.properties"));
	}
	
	public static void save()
	{
		save(VideoProperties.class, new File("video.properties"));
	}

	/**
	 * Calculate the scale of the y-axis relative to the x-axis for a certain shape window on a certain shape screen.
	 * 
	 * @param w The width of the window.
	 * @param h The height of the window.
	 * @return The correct x/y aspect ratio for a w*h window on an ASPECT_RATIO screen at the current resolution.
	 */
	public static float calculateAspectRatio(int w, int h)
	{
		if ((w == 0) || (h == 0))
			return 1;

		final String[] parts = ASPECT_RATIO.split(":");
		float pixelAR;
		
		if (parts.length >= 2)
			pixelAR = Float.parseFloat(parts[1]) / Float.parseFloat(parts[0]);
		else
			pixelAR = Float.parseFloat(parts[0]);
		
		DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
		
		pixelAR *= (float)mode.getWidth() / mode.getHeight();

		if (FULLSCREEN)
		{
			return pixelAR;
		}

		return pixelAR * h / w;
	}
}
